package com.lv.phuotbacnam.ui.fragment;

import java.util.ArrayList;

import com.lv.phuotbacnam.R;


import android.annotation.SuppressLint;
import android.content.Context;
import android.text.Layout;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class MyAdapter1 extends ArrayAdapter<Model> {

		private final Context context;
		private final ArrayList<Model> modelsArrayList;
		private  int color ;

		public MyAdapter1(Context context, ArrayList<Model> modelsArrayList,int colo) {
			 
			super(context, R.layout.target_item1, modelsArrayList);
			this.color= colo;
			this.context = context;
			this.modelsArrayList = modelsArrayList;
		}
		
		@SuppressLint("ResourceAsColor")
		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
		    
			// 1. Create inflater 
			LayoutInflater inflater = (LayoutInflater) context
		        .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		    
			// 2. Get rowView from inflater
			
			View rowView = null;
			if(!modelsArrayList.get(position).isGroupHeader()){
				rowView = inflater.inflate(R.layout.target_item1, parent, false);
			
				// 3. Get icon,title & counter views from the rowView
				ImageView imgView = (ImageView) rowView.findViewById(R.id.item_icon); 
				TextView titleView = (TextView) rowView.findViewById(R.id.item_title);
				TextView counterView = (TextView) rowView.findViewById(R.id.item_counter);
		    
			    // 4. Set the text for textView 
			    imgView.setImageResource(modelsArrayList.get(position).getIcon());
			    titleView.setText(modelsArrayList.get(position).getTitle());
			    //titleView.
			    if (modelsArrayList.get(position).getColor()!=0)
			    rowView.setBackgroundColor(modelsArrayList.get(position).getColor());
			    
			//  titleView.setBackgroundColor(color);
			    counterView.setVisibility(View.GONE);
			    counterView.setText(modelsArrayList.get(position).getCounter());
			   
			}
			
		   
		    // 5. retrn rowView
		    return rowView;
		}
}